<template>
	<view class="main">
		<view class="bill">
			<view class="item">
				<view class="title">
					当月总金额
				</view>
				<view class="number">
					￥{{amount.in}}
				</view>
			</view>
			<view class="item">
				<view class="title">
					当月提现金额
				</view>
				<view class="number">
					￥{{amount.out}}
				</view>
			</view>
		</view>
		<view class="month">
			<view class="title">
				请选择月份
			</view>
			<picker class="time" mode="date" fields="month" @change="selectType">
				<view>{{time}}</view>
			</picker>
		</view>
		<view class="list" v-for="item in list">
			<view class="content">
				<view class="name">
					{{item.product_name}}
				</view>
				<view class="">
					{{item.createtime}}
				</view>
			</view>
			<view class="amount">
				+{{item.money}}
				<!-- <image class="icon" src="../../static/get.png" mode="widthFix"></image> -->
			</view>
		</view>
		<u-empty v-if="list.length==0" text="暂无数据" mode="list"></u-empty>
	</view>
</template>

<script>
	import {
		monthRecord
	} from "@/api/index.js"
	export default {
		data() {
			return {
				time: '',
				amount: {
					in: 0,
					out: 0
				},
				list: []
			};
		},
		mounted() {
			var currentDate = new Date();
			var currentYear = currentDate.getFullYear();
			var currentMonth = currentDate.getMonth() + 1; // 月份从0开始，所以要加1
			if (currentMonth < 10) {
				currentMonth = "0" + currentMonth
			}
			this.time = currentYear + "-" + currentMonth
			this.getDetail()
		},
		methods: {
			//获取收益明细
			getDetail() {
				let params = {
					month: this.time,
					page: this.page,
					page_size: 10,
				}
				monthRecord(params).then(res => {
					if (res.code == 1) {
						this.amount = res.data
						this.list = this.list.concat(res.data.list)
						uni.stopPullDownRefresh();
					}
				})
			},
			enablePullDownRefresh() {
				this.page++
				this.getMyCustomer()
			},
			selectType(e) {
				this.time = e.detail.value
				if (e.detail.value == 0) {
					this.level = ''
				} else if (e.detail.value == 1) {
					this.level = 2
				} else {
					this.level = 3
				}
				this.page = 1
				this.list = []
				this.getDetail()
			},
			detail() {
				uni.navigateTo({
					url: "/pages/wallet/monthDetail"
				})
			}
		}
	}
</script>

<style lang="scss">
	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fff;
		margin-bottom: 20rpx;
		padding: 26rpx;
		color: #656565;

		.content {
			font-size: 28rpx;
		}

		.amount {
			font-size: 30rpx;
			display: flex;
			align-items: center;
			color: #d4237a;

			.icon {
				width: 40rpx;
				margin-left: 20rpx;
			}
		}
	}

	.bill {
		background-color: #3B81F3;
		padding: 20rpx 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;

		.item {
			flex: 1;
			color: #fff;
			font-size: 28rpx;
			text-align: center;

			.title {
				font-size: 28rpx;
			}

			.number {
				font-size: 32rpx;
			}
		}

		.item:first-child {
			border-right: 1px solid #fff;
		}
	}

	.month {
		background-color: #fff;
		padding: 26rpx;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		margin-bottom: 20rpx;

		.time {
			flex: 1;
			text-align: right;
		}
	}
</style>